// pages/mackdetail/index.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    inde: 0,
    indexss: 0,
    num:1,
    arrli:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options.id);
    // ------ 商品   ------
    wx.request({
      url: app.globalData.url + '/zkxj/cosmetics/detail',
      data: {
        "goodId": options.id,

      },
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        console.log(res);
        if (res.data.data) {
          this.setData({
            arrli: res.data.data
          })
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  onChange(event) {
    console.log(event.detail);
    this.setData({
      num:event.detail
    })
  },
  handlelogname(e) {
    e.currentTarget.dataset['name']
    // console.log(e.currentTarget.dataset['name'])
    // console.log(e.currentTarget.dataset['index'])
    this.setData({
      indexss: e.currentTarget.dataset['index']
    })
  },
  handlelogui(e) {
    e.currentTarget.dataset['name']
    // console.log(e.currentTarget.dataset['name']);
    // console.log(e.currentTarget.dataset['index'])
    this.setData({
      indexss: e.currentTarget.dataset['index']
    })
  },
  handleshow() {
    this.setData({
      show: true
    });
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  handletobuy() {
    let pularr=this.data.arrli
    console.log(pularr);
    let arr=[]
  //  console.log(pularr.colorList[this.data.indexss].goodId);
   if(pularr.colorList.length){
    arr.push({
      coverPic: pularr.coverPic,
    goodAreaDetail: 5,
    id:pularr.colorList[this.data.indexss].goodId,
    level: null,
    name: pularr.name,
    num: this.data.num,
    oldPrice: pularr.colorList[this.data.indexss].price,
    oldpric:  pularr.colorList[this.data.indexss].price,
    price:   pularr.colorList[this.data.indexss].price,
     })
     // 计算总价
    var zonjia=pularr.colorList[this.data.indexss].price*this.data.num
   }else if(pularr.attrList.length){
     console.log(pularr.attrList);
    arr.push({
      coverPic: pularr.coverPic,
    goodAreaDetail: 5,
    id: pularr.attrList[this.data.indexss].goodId,
    level: null,
    name: pularr.name,
    num: this.data.num,
    oldPrice: pularr.attrList[this.data.indexss].price,
    oldpric: pularr.attrList[this.data.indexss].price,
    price:  pularr.attrList[this.data.indexss].price,
     })
    //  计算总价
    var zonjia=pularr.attrList[this.data.indexss].price*this.data.num
   }
  
      console.log(arr);
   
    

    var detailsData = JSON.stringify(arr);
    detailsData = encodeURIComponent(detailsData);
    wx.navigateTo({
      url: `/pages/seaccounts/index?arr=${detailsData}&sum=${JSON.stringify(zonjia)}&type=0&upgradeLevel=0`
    })
    console.log(zonjia);



  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})